package com.xm.xmapp.customview;

import android.text.Editable;
import android.text.TextWatcher;

public class MyTextWatcher implements TextWatcher {

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {

	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {

	}

	@Override
	public void afterTextChanged(Editable edt) {
		String temp = edt.toString();
		if (edt.toString().getBytes().length != edt.length()) {
			edt.delete(temp.length() - 1, temp.length());
		}
		try {
			temp = edt.toString();
			String tem = temp.substring(temp.length() - 1, temp.length());
			char[] temC = tem.toCharArray();
			int mid = temC[0];
			if (mid >= 48 && mid <= 57) {// 数字
				return;
			}
			if (mid >= 65 && mid <= 90) {// 大写字母
				return;
			}
			if (mid >= 97 && mid <= 122) {// 小写字母
				return;
			}
			edt.delete(temp.length() - 1, temp.length());
		} catch (Exception e) {
			try {
				throw new Exception("输入数据出错");
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

}
